<?php

use yii\helpers\Html;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model common\models\BasMember */

$this->title = '个人信息';
?>
    <style>
        .bas-member-view {
            width: 550px;
        }
    </style>
    <div style="margin: 10px 0 20px 0">
        <?= Html::button('修改密码', ['class' => 'btn btn-success change-ps']) ?>
    </div>
    <div class="bas-member-view">

        <table id="w0" class="table table-striped table-bordered detail-view">
            <tbody>
            <tr>
                <th>分馆权限</th>
                <td><?= $data['title'] ?></td>
            </tr>
            <tr>
                <th>分馆有效期</th>
                <td><?= $data['time'] ?></td>
            </tr>
            <tr>
                <th>用户名</th>
                <td><?= $data['username'] ?></td>
            </tr>
            <tr>
                <th>电话</th>
                <td><?= $data['phone'] ?></td>
            </tr>

            </tbody>
        </table>
    </div>
    <div id="open" style="display: none;">
        <div style="text-align: center;margin: 15px 20px;">
            <input type="text" name="" id="old_ps" style="display: block;width: 100%;" placeholder="请输入旧密码">
        </div>
        <div style="text-align: center;margin: 15px 20px;">
            <input type="text" name="" id="new_ps" style="display: block;width: 100%;" placeholder="请输入新密码">
        </div>
        <div style="text-align: center;margin: 15px 20px;">
            <input type="text" name="" id="new2_ps" style="display: block;width: 100%;" placeholder="请再次输入新密码">
        </div>
        <div style="display: flex;justify-content: center;margin-top: 15px">
            <span id="change_password" class='btn btn-primary' type="button">确认修改</span>
        </div>
    </div>
    <script>
        <?php $this->beginBlock('js_ok_remove') ?>
        //专题列表
        $(document).on('click', '.change-ps', function () {

            layer.open({
                type: 1,
                title: "专题列表",
                area: ["350px", "220px"],
                content: $('#open'),
            });

        });
        //确认添加
        $(document).on('click', '#change_password', function () {
            let old_ps = $('#old_ps').val();
            let new_ps = $('#new_ps').val();
            let new2_ps = $('#new2_ps').val();
            if (old_ps && new_ps) {
                layer.confirm('确认修改密码？', {icon: 3, title: ''}, function (index) {
                    $.ajax({
                        url: '<?=Url::toRoute('change-ps')?>',//'/resource/resource/upload-file'
                        type: 'POST',
                        data: {
                            old_ps: old_ps,
                            new_ps: new_ps,
                            new2_ps: new2_ps,
                        },
                        dataType: "json",
                        success: function (msg) {

                            if (msg.status == 200) {
                                layer.msg(msg['msg'], {icon: 1, time: 1000}, function () {
                                    layer.closeAll();
                                });
                            } else {
                                layer.msg(msg['msg'], {icon: 2, time: 1000});
                            }
                        },
                        error: function () {
                        },
                    });
                    layer.close(index);
                });
            }
        });
        <?php $this->endBlock() ?>
    </script>
<?php $this->registerJs($this->blocks['js_ok_remove'], \yii\web\View::POS_END); ?>